#include "UDPServer.hpp"
#include "Route.hpp"
#include "ThreadPool.hpp"
#include <functional>
#include <iostream>
using namespace ThreadPoolModule;

using task_t = std::function<void()>;

/* 调用方式 ./udpsever port*/
int main(int argc, char *argv[])
{
    if(argc != 2)
    {
        LOG(LogLevel::ERROR) << "./udpsever port";
        return -1;
    }

    uint16_t severport = std::stoi(argv[1]);

    /* 日志显示器打印策略 */
    Enable_Console_Log_Strategy() 

    /* 路由服务 */
    Route r;

    /* 线程池服务 */
    auto tp = ThreadPool<task_t>::GetInstance();


    std::unique_ptr<UDPSever> usvr = std::make_unique<UDPSever>(severport, [&r, &tp](int sockfd, const std::string &message, InterAddr &peer){
        task_t t = std::bind(&Route::MessageRoute, &r, sockfd, message, peer);
        tp->Enqueue(t);
    });

    usvr->Init();
    usvr->Start();

    return 0;
}